using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Media;

namespace TxTReader.Services
{
    /// <summary>
    /// 主题信息
    /// </summary>
    public class ThemeInfo
    {
        public string Name { get; set; } = string.Empty;
        public string DisplayName { get; set; } = string.Empty;
        public Brush WindowBackground { get; set; } = Brushes.White;
        public Brush MenuBackground { get; set; } = SystemColors.MenuBrush;
        public Brush MenuForeground { get; set; } = SystemColors.MenuTextBrush;
        public Brush ToolBarBackground { get; set; } = SystemColors.ControlBrush;
        public Brush StatusBarBackground { get; set; } = SystemColors.ControlBrush;
        public Brush StatusBarForeground { get; set; } = SystemColors.ControlTextBrush;
        public Brush TextBackground { get; set; } = Brushes.White;
        public Brush TextForeground { get; set; } = Brushes.Black;
        public string FontFamily { get; set; } = "Consolas";
        public double FontSize { get; set; } = 12;
    }

    /// <summary>
    /// 主题服务
    /// </summary>
    public class ThemeService
    {
        private static readonly Dictionary<string, ThemeInfo> _themes = new Dictionary<string, ThemeInfo>();
        private static string _currentTheme = "Classic";
        public static event Action<ThemeInfo>? ThemeChanged;

        static ThemeService()
        {
            InitializeThemes();
        }

        /// <summary>
        /// 获取当前主题
        /// </summary>
        public static string CurrentTheme => _currentTheme;

        /// <summary>
        /// 获取所有主题
        /// </summary>
        public static Dictionary<string, ThemeInfo> Themes => _themes;

        /// <summary>
        /// 获取当前主题信息
        /// </summary>
        public static ThemeInfo GetCurrentTheme()
        {
            return _themes.ContainsKey(_currentTheme) ? _themes[_currentTheme] : _themes["Classic"];
        }

        /// <summary>
        /// 设置主题
        /// </summary>
        public static void SetTheme(string themeName)
        {
            if (_themes.ContainsKey(themeName))
            {
                _currentTheme = themeName;
                ThemeChanged?.Invoke(_themes[_currentTheme]);
            }
        }

        /// <summary>
        /// 初始化所有主题
        /// </summary>
        private static void InitializeThemes()
        {
            // 经典主题 - 默认Windows样式
            _themes["Classic"] = new ThemeInfo
            {
                Name = "Classic",
                DisplayName = "经典主题",
                WindowBackground = SystemColors.WindowBrush,
                MenuBackground = SystemColors.MenuBrush,
                MenuForeground = SystemColors.MenuTextBrush,
                ToolBarBackground = SystemColors.ControlBrush,
                StatusBarBackground = SystemColors.ControlBrush,
                StatusBarForeground = SystemColors.ControlTextBrush,
                TextBackground = Brushes.White,
                TextForeground = Brushes.Black,
                FontFamily = "Consolas",
                FontSize = 12
            };

            // 绿色终端主题 - 复古终端风格（优化护眼）
            _themes["GreenTerminal"] = new ThemeInfo
            {
                Name = "GreenTerminal",
                DisplayName = "绿色终端",
                WindowBackground = new SolidColorBrush(Color.FromRgb(0, 0, 0)),
                MenuBackground = new SolidColorBrush(Color.FromRgb(0, 20, 0)),
                MenuForeground = new SolidColorBrush(Color.FromRgb(0, 200, 0)),
                ToolBarBackground = new SolidColorBrush(Color.FromRgb(0, 20, 0)),
                StatusBarBackground = new SolidColorBrush(Color.FromRgb(0, 20, 0)),
                StatusBarForeground = new SolidColorBrush(Color.FromRgb(0, 200, 0)),
                TextBackground = new SolidColorBrush(Color.FromRgb(0, 0, 0)),
                TextForeground = new SolidColorBrush(Color.FromRgb(0, 200, 0)),
                FontFamily = "Consolas",
                FontSize = 12
            };

            // 琥珀主题 - 复古琥珀色（优化护眼）
            _themes["Amber"] = new ThemeInfo
            {
                Name = "Amber",
                DisplayName = "琥珀主题",
                WindowBackground = new SolidColorBrush(Color.FromRgb(20, 20, 15)),
                MenuBackground = new SolidColorBrush(Color.FromRgb(30, 25, 15)),
                MenuForeground = new SolidColorBrush(Color.FromRgb(255, 180, 50)),
                ToolBarBackground = new SolidColorBrush(Color.FromRgb(30, 25, 15)),
                StatusBarBackground = new SolidColorBrush(Color.FromRgb(30, 25, 15)),
                StatusBarForeground = new SolidColorBrush(Color.FromRgb(255, 180, 50)),
                TextBackground = new SolidColorBrush(Color.FromRgb(20, 20, 15)),
                TextForeground = new SolidColorBrush(Color.FromRgb(255, 180, 50)),
                FontFamily = "Consolas",
                FontSize = 12
            };

            // 蓝色主题 - 复古蓝色（优化护眼）
            _themes["Blue"] = new ThemeInfo
            {
                Name = "Blue",
                DisplayName = "蓝色主题",
                WindowBackground = new SolidColorBrush(Color.FromRgb(0, 0, 40)),
                MenuBackground = new SolidColorBrush(Color.FromRgb(0, 0, 80)),
                MenuForeground = new SolidColorBrush(Color.FromRgb(150, 200, 255)),
                ToolBarBackground = new SolidColorBrush(Color.FromRgb(0, 0, 80)),
                StatusBarBackground = new SolidColorBrush(Color.FromRgb(0, 0, 80)),
                StatusBarForeground = new SolidColorBrush(Color.FromRgb(150, 200, 255)),
                TextBackground = new SolidColorBrush(Color.FromRgb(0, 0, 40)),
                TextForeground = new SolidColorBrush(Color.FromRgb(150, 200, 255)),
                FontFamily = "Consolas",
                FontSize = 12
            };

            // 深色护眼主题 - 现代深色风格
            _themes["DarkEyeCare"] = new ThemeInfo
            {
                Name = "DarkEyeCare",
                DisplayName = "深色护眼",
                WindowBackground = new SolidColorBrush(Color.FromRgb(30, 30, 30)),
                MenuBackground = new SolidColorBrush(Color.FromRgb(40, 40, 40)),
                MenuForeground = new SolidColorBrush(Color.FromRgb(200, 200, 200)),
                ToolBarBackground = new SolidColorBrush(Color.FromRgb(40, 40, 40)),
                StatusBarBackground = new SolidColorBrush(Color.FromRgb(40, 40, 40)),
                StatusBarForeground = new SolidColorBrush(Color.FromRgb(200, 200, 200)),
                TextBackground = new SolidColorBrush(Color.FromRgb(30, 30, 30)),
                TextForeground = new SolidColorBrush(Color.FromRgb(200, 200, 200)),
                FontFamily = "Consolas",
                FontSize = 12
            };

            // 纯白主题 - 简洁明亮
            _themes["PureWhite"] = new ThemeInfo
            {
                Name = "PureWhite",
                DisplayName = "纯白主题",
                WindowBackground = Brushes.White,
                MenuBackground = Brushes.White,
                MenuForeground = new SolidColorBrush(Color.FromRgb(60, 60, 60)),
                ToolBarBackground = Brushes.White,
                StatusBarBackground = Brushes.White,
                StatusBarForeground = new SolidColorBrush(Color.FromRgb(60, 60, 60)),
                TextBackground = Brushes.White,
                TextForeground = new SolidColorBrush(Color.FromRgb(60, 60, 60)),
                FontFamily = "Consolas",
                FontSize = 12
            };

            // 米黄护眼主题 - 温暖护眼
            _themes["CreamEyeCare"] = new ThemeInfo
            {
                Name = "CreamEyeCare",
                DisplayName = "米黄护眼",
                WindowBackground = new SolidColorBrush(Color.FromRgb(255, 253, 240)),
                MenuBackground = new SolidColorBrush(Color.FromRgb(255, 253, 240)),
                MenuForeground = new SolidColorBrush(Color.FromRgb(80, 70, 50)),
                ToolBarBackground = new SolidColorBrush(Color.FromRgb(255, 253, 240)),
                StatusBarBackground = new SolidColorBrush(Color.FromRgb(255, 253, 240)),
                StatusBarForeground = new SolidColorBrush(Color.FromRgb(80, 70, 50)),
                TextBackground = new SolidColorBrush(Color.FromRgb(255, 253, 240)),
                TextForeground = new SolidColorBrush(Color.FromRgb(80, 70, 50)),
                FontFamily = "Consolas",
                FontSize = 12
            };
        }
    }
}
